package com.jxaummd.mushroom.main.common.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.jxaummd.mushroom.R;
import com.jxaummd.mushroom.core.app.account.AccountManager;
import com.jxaummd.mushroom.core.app.activity.ActivityManager;
import com.jxaummd.mushroom.core.base.fragment.PresenterFragment;
import com.jxaummd.mushroom.main.common.contract.LaunchScrollContract;
import com.jxaummd.mushroom.main.common.presenter.LaunchScrollPresenter;
import com.jxaummd.mushroom.ui.launch.LauncherHoderCreator;

import java.util.List;

public class LaunchScrollFragment extends PresenterFragment<LaunchScrollContract.Presenter>
        implements LaunchScrollContract.View {
    private ConvenientBanner<Integer> mConvenientBanner = null;



    @Override
    protected LaunchScrollContract.Presenter initPresenter() {
        return new LaunchScrollPresenter(this);
    }

    @Override
    public Object setLayout() {
        mConvenientBanner = new ConvenientBanner<>(getContext());
        return mConvenientBanner;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {
            mPresenter.start();
    }

    /***
     * 初始化ConcenientBanner
     * @param mipmap 图片资源的List
     */
    @Override
    public void initView(List<Integer> mipmap) {
        mConvenientBanner.setPages(new LauncherHoderCreator(),mipmap)
                .setPageIndicator(new int[]{R.drawable.dot_focus,R.drawable.dot_normal})
                .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL)
                .setOnItemClickListener(position -> {
                    mPresenter.clickItem(position);
                })
                .setCanLoop(false);

    }

    @Override
    public void finishScroll() {
        if (!AccountManager.isSignIn()) {
           startWithPop(new LoginFragment());
        } else {
            Intent intent = new Intent(getProxyActivity(), ActivityManager.getActivity("main"));
            startActivity(intent);
            getProxyActivity().finish();
        }
    }

}
